﻿using UnityEngine;
using System.Collections;

public class SpriteAutoPlay : MonoBehaviour
{
    public Sprite[] sprites;
    public float framesPerSecond;
    private SpriteRenderer spriteRenderer;

    public bool canAutoPlaySprite;
    // Use this for initialization
    void Start()
    {
        canAutoPlaySprite = true;
        spriteRenderer = GetComponent<Renderer>() as SpriteRenderer;
    }

    void AutoPlaySprite()
    {
        if (canAutoPlaySprite)
        {
            int index = (int)(Time.timeSinceLevelLoad * framesPerSecond);
            index = index % sprites.Length;
            spriteRenderer.sprite = sprites[index];
        }
    }

    // Update is called once per frame
    void Update()
    {
        AutoPlaySprite();
    }
}
